#include "Light.h"

Light::Light( float a[4], float d[4], float s[4], bool on , int lightX)
{
	for(int i=0; i<4;++i){
		ambient[i] =a[i];
		diffuse[i] =d[i];
		specular[i]=s[i];
	}
	enabled=on;
	this->lightX=lightX;

	if(enabled)
		enable();

	glLightf(getLightX(), GL_CONSTANT_ATTENUATION,  0);
	glLightf(getLightX(), GL_LINEAR_ATTENUATION,    1);
	glLightf(getLightX(), GL_QUADRATIC_ATTENUATION, 0);
}

float * Light::getAmbient()
{
	return ambient;
}

float * Light::getDiffuse()
{
	return diffuse;
}

float * Light::getSpecular()
{
	return specular;
}

void Light::enable()
{
	enabled=true;
	glEnable(getLightX());
}

void Light::disable()
{
	enabled=false;
	glDisable(getLightX());
}

int Light::getLightX()
{
	switch(lightX){
		case 0:
			return GL_LIGHT0;
			break;
		case 1:
			return GL_LIGHT1;
			break;
		case 2:
			return GL_LIGHT2;
			break;
		case 3:
			return GL_LIGHT3;
			break;
		case 4:
			return GL_LIGHT4;
			break;
		case 5:
			return GL_LIGHT5;
			break;
		case 6:
			return GL_LIGHT6;
			break;
		case 7:
			return GL_LIGHT7;
			break;
	}
}


bool Light::isEnabled()
{
	return enabled;
		
}

void Light::switchState()
{
	if(isEnabled())
		disable();
	else
		enable();
}

void Light::setAttenuation( int v[3] )
{
	glLightf(getLightX(), GL_CONSTANT_ATTENUATION,   v[0]);
	glLightf(getLightX(), GL_LINEAR_ATTENUATION,     v[1]);
	glLightf(getLightX(), GL_QUADRATIC_ATTENUATION,  v[2]);
}
